import Vuex from 'vuex'
import Vue from "vue";
Vue.use(Vuex)
import {getMusicLyricAPI, getUserDetailAPI} from '@/api';
const store = new Vuex.Store({
    state: {
      playList:[{
        al: {
          id: 143943146,
          name: '你要的不是我',
          pic: 109951167337920220,
          picUrl: 'http://p3.music.126.net/NCmvLBBtdQkqZUu-Jgj7SQ==/109951167337920217.jpg',
          pic_str: '109951167337920217',
        },
        id: 1941246316,
        ar: [
          {
            name: '刘恋',
          }],
      }],
      playListIndex: 0,
      isBtnShow: true,
      detailShow: false,
      lyrIcList: {},
      currentTime: 0,
      duration: 0,
      audio: null,
      isPlaying: false,
      isLogin: false,
      token: '',
      user: {},
    },
    mutations: {
      changUser(state, value) {
        state.user = value;
        localStorage.setItem('user', JSON.stringify(state.user));
      },
      changeToken(state, value) {
        state.token = value;
        localStorage.setItem('token', JSON.stringify(state.token));

      },
      loginValue(state, value) {
        state.isLogin = value;

      },
      pushPlayList(state, value) {
        state.playList.push(value);
      },
      updateDuration(state, value) {
        state.duration = value;
      },
      updateCurrentTime(state, value) {
        state.currentTime = value;
        // console.log(state.currentTime)
      },
      updateIsbtnShow(state, value) {
        state.isBtnShow = value;
        console.log('isbtnshow', state.isBtnShow);
      },
      updatePlayList(state,value){
        state.playList = value;
        console.log(state.playList);

      },
      updatePlayListIndex(state, value) {
        state.playListIndex = value;
        console.log('state.playListIndex', state.playListIndex);
      },
      updateDetailShow(state) {
        state.detailShow = !state.detailShow;
      },
      updateLyricList(state, value) {
        state.lyrIcList = value;

      }, setAudio(state, audio) {
        state.audio = audio;
      },
      play(state) {
        console.log('state.audio', state.audio);
        if (state.audio) {
          state.audio.play();
          state.isPlaying = true;
          state.isBtnShow = false;
        }

      },
      pause(state) {
        if (state.audio) {
          state.audio.pause()
          state.isPlaying = false
          state.isBtnShow =true
        }
      }


    },
    actions: {
      async getLyric(context, value) {
        let res = await getMusicLyricAPI(value);
        // console.log(res);
        context.commit('updateLyricList', res.data.lrc);
      },
      async getLogin(context, value) {
        let res = await getUserDetailAPI(value);
        return res;

      },
    },

  modules:{}
  })

  export default store